package gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.io.File;
import java.util.HashMap;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JRadioButton;
import javax.swing.JCheckBox;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;

import code.Language;
import code.MessageAuthenticationCode;
import code.Settings;

public class DataIntegrityCreateFile extends JPanel {

	private static final long serialVersionUID = 1L;
	Color generate = new Color(59, 89, 152);
	private JLabel jLabel = null;
	private JButton jButton = null;
	private JLabel jLabel1 = null;
	private JLabel jLabel2 = null;
	private JLabel jLabel3 = null;
	private JCheckBox jCheckBox = null;
	private JLabel jLabel4 = null;
	private JTextField jTextField = null;
	private JLabel jLabel5 = null;
	private JScrollPane jScrollPane = null;
	private JTextArea jTextArea = null;
	private JRadioButton jRadioButton = null;
	private JRadioButton jRadioButton1 = null;
	private JLabel jLabel6 = null;
	ButtonGroup rbgroup = new ButtonGroup();
	ATOCOmain atocoframe;
	String nextclass;
	MessageAuthenticationCode mc = new MessageAuthenticationCode();
	Color TAc = new Color(246, 250, 250);
	Color c= new Color(0x80, 0x80, 0xFF);
	private JLabel jLabel7 = null;
	private HashMap labels;
	private Settings s;
	/**
	 * This is the default constructor
	 */
	public DataIntegrityCreateFile(ATOCOmain atocoframe) {
		super();
		s = new Settings();
		Language l = new Language();
		labels = l.changeLanguage((String) s.global.get("language"), "DataIntegrityCreateFile", (String) s.global.get("installPath"));
		this.atocoframe=atocoframe;
		initialize();
	}


	public DataIntegrityCreateFile passclass(){
		return this;
	}
	private void initialize() {
		jLabel7 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/accepticon.gif"));
		jLabel7.setBounds(new Rectangle(40, 211, 25, 25));
		jLabel7.setVisible(false);
		jLabel6 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/nextmiddle.gif"));
		jLabel6.setBounds(new Rectangle(235, 143, 56, 46));
		jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				if(nextclass != null){
					if(nextclass.equalsIgnoreCase("newkeygui")){
						atocoframe.contentPane(new DataIntegrityCreateKey(atocoframe, passclass()));
					}else if(nextclass.equalsIgnoreCase("selectkeygui")){
						atocoframe.contentPane(new DataIntegrityKeyList(atocoframe, passclass()));
					}
				}

			}
		});
		jLabel5 = new JLabel();
		jLabel5.setBounds(new Rectangle(515, 65, 88, 16));
		jLabel5.setText((String) labels.get("jLabel5"));
		jLabel5.setForeground(c);
		jLabel5.setFont(new java.awt.Font("Arial", Font.BOLD, 10));
		jLabel4 = new JLabel();
		jLabel4.setBounds(new Rectangle(30, 270, 38, 16));
		jLabel4.setText("MAC :");
		jLabel3 = new JLabel((String) labels.get("jLabel3"), SwingConstants.CENTER);
		jLabel3.setBounds(new Rectangle(71, 211, 75, 25));
		jLabel3.setForeground(Color.WHITE);
		jLabel3.setBackground(generate);
		jLabel3.setOpaque(true);
		jLabel3.setFont(new Font("Calibri", Font.ROMAN_BASELINE, 15));
		jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				mc.calculateMAC(mc.algorithm, mc.getKey(), mc.keyalias, mc.file);
				jTextField.setText(mc.digestB64);
				mc.store();
				jLabel7.setVisible(true);
			}
		});
		jLabel2 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg"));
		jLabel2.setBounds(new Rectangle(40, 166, 25, 25));
		jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				jTextArea.setText((String) labels.get("oldkey"));
			}
		});
		jLabel1 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg"));
		jLabel1.setBounds(new Rectangle(40, 139, 25, 25));
		jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				jTextArea.setText((String) labels.get("newkey"));
			}
		});
		jLabel = new JLabel();
		jLabel.setBounds(new Rectangle(30, 15, 640, 16));
		jLabel.setText((String) labels.get("datamain"));
		this.setSize(757, 479);
		this.setLayout(null);
		this.add(jLabel, null);
		this.setBackground(Color.WHITE);
		this.add(getJButton(), null);
		this.add(jLabel1, null);
		this.add(jLabel2, null);
		this.add(jLabel3, null);
		this.add(getJCheckBox(), null);
		this.add(jLabel4, null);
		this.add(getJTextField(), null);
		this.add(jLabel5, null);
		this.add(getJScrollPane(), null);
		this.add(getJRadioButton(), null);
		this.add(getJRadioButton1(), null);
		this.add(jLabel6, null);
		this.add(jLabel7, null);
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(30, 61, 162, 51));
			jButton.setText((String) labels.get("jButton"));
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); 
					browse();
				}
			});
		}
		return jButton;
	}

	public void browse(){
		JFileChooser fc = new JFileChooser(); 
		fc.setDialogTitle("Title");
		fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
		fc.setMultiSelectionEnabled(true);
		fc.showOpenDialog(this); 

		try { 
			// Open an input stream 
			File f= fc.getSelectedFile();
			//File[] f =fc.getSelectedFiles();
			System.out.println(f);
			if(!f.equals("null")){
				String s=f.getPath();
				mc.file=s;

			}

		}catch(Exception e){

		}

	}
	/**
	 * This method initializes jCheckBox	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBox() {
		if (jCheckBox == null) {
			jCheckBox = new JCheckBox();
			jCheckBox.setBounds(new Rectangle(165, 211, 70, 23));
			jCheckBox.setText((String) labels.get("jCheckBox"));
			jCheckBox.setSelected(true);
		}
		return jCheckBox;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(31, 301, 286, 25));
			jTextField.setForeground(generate);
		}
		return jTextField;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(424, 89, 302, 333));
			jScrollPane.setViewportView(getJTextArea());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new JTextArea();
			jTextArea.setBackground(TAc);
			jTextArea.setLineWrap(true);
			jTextArea.setWrapStyleWord(true);
			jTextArea.setEditable(false);
		}
		return jTextArea;
	}

	/**
	 * This method initializes jRadioButton	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton() {
		if (jRadioButton == null) {
			jRadioButton = new JRadioButton();
			jRadioButton.setBounds(new Rectangle(72, 141, 160, 21));
			jRadioButton.setText((String) labels.get("jRadioButton"));
			jRadioButton.setSelected(true);
			nextclass="newkeygui";
			jRadioButton.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e){
					if(jRadioButton.isSelected())
					{
						nextclass="newkeygui";
						System.out.println("radiobutton");
					}

				}
			});
			rbgroup.add(jRadioButton);
		}
		return jRadioButton;
	}

	/**
	 * This method initializes jRadioButton1	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton1() {
		if (jRadioButton1 == null) {
			jRadioButton1 = new JRadioButton();
			jRadioButton1.setBounds(new Rectangle(71, 169, 160, 21));
			jRadioButton1.setText((String) labels.get("jRadioButton1"));
			jRadioButton1.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e){
					if(jRadioButton1.isSelected())
					{
						nextclass="selectkeygui";
						System.out.println("radiobutton1");
					}

				}
			});
			rbgroup.add(jRadioButton1);
		}
		return jRadioButton1;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
